package com.renjibo.teawithmilkgoods;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.renjibo.teawithmilkgoods.adapters.MyRecycleAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RecycleViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_view);
        RecyclerView recyclerView= (RecyclerView) findViewById(R.id.recycleView);
        StaggeredGridLayoutManager layoutManager=new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        //linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(new MyRecycleAdapter(initData()));
    }
    public List<String> initData(){

        List<String> list=new ArrayList<>();
        for(int i=0;i<100;i++){
            list.add(getRandomLengthName("小明"+i+"号"));
        }
        return list;
    }
    private String getRandomLengthName(String name){
        Random random=new Random();
        int length=random.nextInt(60)+1;
        StringBuilder builder=new StringBuilder();
        for(int i=0;i<length;i++){
            builder.append(name);
        }
        return  builder.toString();
    }
}
